home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / global-one-water.swf / scripts / __Packages / KidMc.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  5.5 KB  |  204 lines

  1. class KidMc extends GameObject
  2. {
  3.    var sweat;
  4.    var pose;
  5.    var engine;
  6.    var exclamation;
  7.    var stamina;
  8.    var kid;
  9.    var onPress;
  10.    var onRollOver;
  11.    var onDragOver;
  12.    var onRollOut;
  13.    var onDragOut;
  14.    var inner;
  15.    var isDownHill;
  16.    var isOver = false;
  17.    static var POSE_BUFFER = 0.1;
  18.    static var DOWN = "forward";
  19.    static var UP = "back";
  20.    static var SIDE = "side";
  21.    static var IDLE = "idle";
  22.    static var RIGHT = "right";
  23.    static var LEFT = "left";
  24.    static var OK = "ok";
  25.    static var TIRED = "tired";
  26.    static var KNACKERED = "knackered";
  27.    static var SWEAT = "sweat";
  28.    static var NO_SWEAT = "noSweat";
  29.    var dir = KidMc.DOWN;
  30.    function KidMc()
  31.    {
  32.       super();
  33.       this.stop();
  34.       this.sweat.stop();
  35.       this.pose = [KidMc.LEFT,KidMc.IDLE];
  36.       this.init(this.engine);
  37.    }
  38.    function onLoad()
  39.    {
  40.       this.exclamation.init(this.engine);
  41.       this.stamina.init(this.engine);
  42.    }
  43.    function update()
  44.    {
  45.       super.update();
  46.       this.stamina.update(this.kid.stamina / this.kid.maxStamina);
  47.       if(!this.kid.happy && !this.kid.knackered)
  48.       {
  49.          var _loc4_ = (1 - this.kid.stamina / this.kid.maxStamina - Kid.TIRED_POINT) * (1 / Kid.EXHAUSTED_POINT);
  50.          var _loc3_ = 1 + Math.floor(_loc4_ * this.exclamation.inner.inner._totalframes);
  51.          this.exclamation.inner.inner.gotoAndStop(_loc3_);
  52.       }
  53.       this.exclamation.convertScale();
  54.    }
  55.    function joinedPump()
  56.    {
  57.       this.onPress = this.doLeavePump;
  58.       this.onRollOver = this.onDragOver = this.rolledOver;
  59.       this.onRollOut = this.onDragOut = this.rolledOut;
  60.    }
  61.    function leftPump()
  62.    {
  63.       delete this.onPress;
  64.       delete this.onRollOver;
  65.       delete this.onRollOut;
  66.       delete this.onDragOver;
  67.       delete this.onDragOut;
  68.       this.rolledOut();
  69.    }
  70.    function rolledOver()
  71.    {
  72.       this.inner.filters = [GameObject.GLOW_FILTER];
  73.       this.stamina._visible = true;
  74.       this.isOver = true;
  75.    }
  76.    function rolledOut()
  77.    {
  78.       this.inner.filters = [];
  79.       this.stamina._visible = false;
  80.       this.isOver = false;
  81.    }
  82.    function doLeavePump()
  83.    {
  84.       this.kid.leavePump(true);
  85.    }
  86.    function getPoseForAng(ang)
  87.    {
  88.       var _loc1_ = 0.5235987755982988;
  89.       if(ang > - _loc1_ * 5 && ang <= - _loc1_ * 3)
  90.       {
  91.          return [KidMc.LEFT,KidMc.UP];
  92.       }
  93.       if(ang > - _loc1_ * 3 && ang <= - _loc1_)
  94.       {
  95.          return [KidMc.RIGHT,KidMc.UP];
  96.       }
  97.       if(ang > - _loc1_ && ang <= _loc1_)
  98.       {
  99.          return [KidMc.RIGHT,KidMc.SIDE];
  100.       }
  101.       if(ang > _loc1_ && ang <= _loc1_ * 3)
  102.       {
  103.          return [KidMc.RIGHT,KidMc.DOWN];
  104.       }
  105.       if(ang > _loc1_ * 3 && ang <= _loc1_ * 5)
  106.       {
  107.          return [KidMc.LEFT,KidMc.DOWN];
  108.       }
  109.       return [KidMc.LEFT,KidMc.SIDE];
  110.    }
  111.    function doChangePose(ang, pose)
  112.    {
  113.       var _loc1_ = 0.5235987755982988;
  114.       switch(pose.join(""))
  115.       {
  116.          case KidMc.LEFT + KidMc.UP:
  117.             return !(ang + KidMc.POSE_BUFFER > - _loc1_ * 5 && ang - KidMc.POSE_BUFFER <= - _loc1_ * 3);
  118.          case KidMc.RIGHT + KidMc.UP:
  119.             return !(ang + KidMc.POSE_BUFFER > - _loc1_ * 3 && ang - KidMc.POSE_BUFFER <= - _loc1_);
  120.          case KidMc.RIGHT + KidMc.SIDE:
  121.             return !(ang + KidMc.POSE_BUFFER > - _loc1_ && ang - KidMc.POSE_BUFFER <= _loc1_);
  122.          case KidMc.RIGHT + KidMc.DOWN:
  123.             return !(ang + KidMc.POSE_BUFFER > _loc1_ && ang - KidMc.POSE_BUFFER <= _loc1_ * 3);
  124.          case KidMc.LEFT + KidMc.DOWN:
  125.             return !(ang + KidMc.POSE_BUFFER > _loc1_ * 3 && ang - KidMc.POSE_BUFFER <= _loc1_ * 5);
  126.          case KidMc.LEFT + KidMc.SIDE:
  127.             return true;
  128.          default:
  129.             return true;
  130.       }
  131.    }
  132.    function setPos(p)
  133.    {
  134.       if(p.x != this._x || p.y != this._y)
  135.       {
  136.          var _loc3_ = undefined;
  137.          if(!this.isDownHill)
  138.          {
  139.             _loc3_ = Math.atan2(- (p.y - this._y),p.x - this._x);
  140.          }
  141.          else
  142.          {
  143.             _loc3_ = Math.atan2(p.y - this._y,p.x - this._x);
  144.          }
  145.          if(this.doChangePose(_loc3_,this.pose))
  146.          {
  147.             this.pose = this.getPoseForAng(_loc3_);
  148.             if(this.pose[0] == KidMc.LEFT)
  149.             {
  150.                this.xdir = -1;
  151.             }
  152.             else
  153.             {
  154.                this.xdir = 1;
  155.             }
  156.             var _loc4_ = this.pose[1];
  157.             if(this.dir != _loc4_)
  158.             {
  159.                this.setPose(_loc4_);
  160.             }
  161.          }
  162.          this._x = p.x;
  163.          this._y = p.y;
  164.          this.swapDepths(this.getTargetDepth());
  165.       }
  166.       else if(this.dir != KidMc.IDLE)
  167.       {
  168.          this.setPose(KidMc.IDLE);
  169.       }
  170.    }
  171.    function startSweating()
  172.    {
  173.       this.exclamation.setState(KidMc.TIRED);
  174.       this.sweat.gotoAndPlay(KidMc.SWEAT);
  175.    }
  176.    function stopSweating()
  177.    {
  178.       this.exclamation.setState(KidMc.OK);
  179.       this.sweat.gotoAndStop(KidMc.NO_SWEAT);
  180.    }
  181.    function changeKnackered(isKnackered)
  182.    {
  183.       if(isKnackered)
  184.       {
  185.          this.exclamation.setState(KidMc.KNACKERED);
  186.       }
  187.       else
  188.       {
  189.          this.exclamation.setState(KidMc.OK);
  190.       }
  191.       this.setPose(this.dir);
  192.    }
  193.    function setPose(newDir)
  194.    {
  195.       this.dir = newDir;
  196.       this.gotoAndStop((!(this.kid.knackered && !this.kid.leaving) ? "" : KidMc.KNACKERED) + newDir);
  197.       this.kid.setAvatar();
  198.       if(this.isOver)
  199.       {
  200.          this.rolledOver();
  201.       }
  202.    }
  203. }
  204.